import express, { urlencoded } from 'express'//导入express
import cors from 'cors'//配置中间键,允许跨域访问
import { PrismaClient } from '@prisma/client'
// 导入路由
import tenantRouter from './router/tenant.js'
import orderRouter from './router/order.js'
import landlordRouter from './router/landlord.js'
import adminRouter from './router/admin.js'
import billRouter from './router/bill.js'
import fixRouter from './router/fix.js'
import noticeRouter from './router/notice.js'
import roomlRouter from './router/room.js'
// 实例化
const app=express()
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({extended:false}))


// 配置自己的中间键
const db= new PrismaClient()
app.use((req,res,next)=>{
  req.db=db
  res.success=(data,info)=>{
     res.send({successs:true,data,info})
  }
  res.fail=(info)=>{
    res.send({successs:false,info})
  }
  next()
})

// 使用路由
app.use(tenantRouter)
app.use(orderRouter)
app.use(landlordRouter)
app.use(adminRouter)
app.use(billRouter)
app.use(fixRouter)
app.use(noticeRouter)
app.use(roomlRouter)

app.listen(3000,()=>{
  console.log('app is running at prot 3000');
})